# Maintainer: valadaa48 <valadaa48@gmx.com>

buildarch=8

_commit=8867101e509ec9e99c2330b1dbd9830ec9350ffe
_pkgname=libmali
pkgbase=mali-bifrost-g31-libgl
pkgname=("${pkgbase}-gbm" "${pkgbase}-x11-gbm")
pkgver=r6p0.01rel0
pkgrel=1
arch=('aarch64')
url="https://github.com/rockchip-linux/libmali"
license=('Proprietary')
depends=('mesa-libgl')
provides=('mali-bifrost-g31-libgl')
conflicts=('mali-bifrost-g31-libgl')
source=('https://github.com/rockchip-linux/libmali/archive/8867101e509ec9e99c2330b1dbd9830ec9350ffe.tar.gz'
    'mali.conf'
    '50-mali.rules')
md5sums=('a6dd69b5fc330dd24193b851a4feb8d6'
         '40f5104200cfceb12b4623d219646d4e'
         'd22820a21496fe3d9ccbae99643aac96')

_gles_libs=('libMali.so'
        'libEGL.so'
        'libEGL.so.1'
        'libEGL.so.1.0.0'
        'libEGL.so.1.1.0'
        'libGLESv1_CM.so'
        'libGLESv1_CM.so.1'
        'libGLESv1_CM.so.1.1.0'
        'libGLESv2.so'
        'libGLESv2.so.2'
        'libGLESv2.so.2.0.0'
        'libgbm.so'
        'libgbm.so.1')

package_mali-bifrost-g31-libgl-gbm() {
    pkgdesc="Mali GPU library used in Rockchip Platform (gbm)"

    install -d "${pkgdir}"/usr/lib/mali-egl
    install -d "${pkgdir}"/etc/ld.so.conf.d
    install -d "${pkgdir}"/usr/lib/udev/rules.d

    cp -a "${srcdir}"/"${_pkgname}-${_commit}"/lib/aarch64-linux-gnu/libmali-bifrost-g31-rxp0-gbm.so "${pkgdir}"/usr/lib/mali-egl
    cp "${srcdir}"/mali.conf "${pkgdir}"/etc/ld.so.conf.d
    cp "${srcdir}"/50-mali.rules "${pkgdir}"/usr/lib/udev/rules.d

    for lib in ${_gles_libs[@]}
    do
        ln -sf /usr/lib/mali-egl/libmali-bifrost-g31-rxp0-gbm.so "${pkgdir}/usr/lib/mali-egl/$lib"
    done
}

package_mali-bifrost-g31-libgl-x11-gbm() {
    pkgdesc="Mali GPU library used in Rockchip Platform (gbm+x11)"

    install -d "${pkgdir}"/usr/lib/mali-egl
    install -d "${pkgdir}"/etc/ld.so.conf.d
    install -d "${pkgdir}"/usr/lib/udev/rules.d

    cp -a "${srcdir}"/"${_pkgname}-${_commit}"/lib/aarch64-linux-gnu/libmali-bifrost-g31-rxp0-x11-gbm.so "${pkgdir}"/usr/lib/mali-egl
    cp "${srcdir}"/mali.conf "${pkgdir}"/etc/ld.so.conf.d
    cp "${srcdir}"/50-mali.rules "${pkgdir}"/usr/lib/udev/rules.d

    for lib in ${_gles_libs[@]}
    do
        ln -sf /usr/lib/mali-egl/libmali-bifrost-g31-rxp0-x11-gbm.so "${pkgdir}/usr/lib/mali-egl/$lib"
    done
}
